import { actions } from 'mirrorx'
export default {
  name: 'mainModel',
  initialState: {
    userInfo: {},
    verificationState: ''
  },
  reducers: {
    setUserInfo (state, data) {
      return Object.assign({}, state, { userInfo: data })
    },
    setVerificationState (state, data) {
      return Object.assign({}, state, { verificationState: data })
    }
  },
  effects: {
    requestUserInfo (type) {
      global.T.ajax({
        url: '/getUserInfo',
        notip: true,
        noJump: true
      }).then((result) => {
        if (result.success) {
          let data = result.value || {}
          actions.mainModel.setUserInfo(data)
        }
      })
    },
    requestVerificationState () {
      global.T.ajax({
        url: '/api/uc/user/getChannelInfo',
        notip: true,
        noJump: true
      }).then((result) => {
        if (result.success) {
          let data = result.data || {}
          actions.mainModel.setVerificationState(data.verificationState || '')
          actions.mainModel.setUserInfo(data || {})
          if (data.userId) {
            actions.menuModel.getGrantedMenus(data.userId)
          }
        }
      })
    }
  }
}
